﻿using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace VsExt.WorkItemVisualizer
{
    /// <summary>
    /// Used to construct the hyperlinks shown on the nodes
    /// </summary>
    internal static class UrlHelper
    {
        /// <summary>
        /// Returns the URL for the changeset link including a placeholder for the changeset ID
        /// </summary>
        /// <param name="wis">The work item store</param>
        /// <returns>A url to a changeset - but not an actual changeset - the changeset ID is a placeholder</returns>
        internal static string GetTWAChangesetBaseUrl(WorkItemStore wis)
        {
            string baseUri = GetTWABaseUrl(wis);
            baseUri += "/UI/Pages/Scc/ViewChangeset.aspx?changeset={0}";
            return baseUri;
        }

        /// <summary>
        /// Returns the Url for a work item in TWA
        /// </summary>
        /// <param name="wis">The work item store</param>
        /// <returns>A placeholder Url to a work item details page</returns>
        internal static string GetTWAWorkItemBaseUrl(WorkItemStore wis)
        {
            string baseUri = GetTWABaseUrl(wis);
            baseUri += "/UI/Pages/WorkItems/WorkItemEdit.aspx?id={0}";
            return baseUri;
        }

        /// <summary>
        /// Returns the base Uri for Team Web Access
        /// </summary>
        /// <param name="wis">The work item store</param>
        /// <returns>The base Uri for TWA <example>http://[server]:[port]/tfs/web</example></returns>
        private static string GetTWABaseUrl(WorkItemStore wis)
        {
            TswaClientHyperlinkService hyperlinkService = wis.TeamProjectCollection.GetService<TswaClientHyperlinkService>();
            return hyperlinkService.GetHomeUrl().ToString();
        }
    }
}